package com.jiguang.property.controller;


import com.jiguang.property.annotation.Log;
import com.jiguang.property.dto.UserInfoDTO;
import com.jiguang.property.service.UserService;
import com.jiguang.property.utils.Result;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author testjava
 * @since 2025-01-19
 */
@RestController
@RequestMapping("/userInfo")
@CrossOrigin
public class UserController {
    @Autowired
    private UserService userService;

    @ApiOperation(value = "登录")
    @PostMapping("login")
    public Result login(@RequestBody UserInfoDTO userInfoDto) {
        //登录
        return userService.login(userInfoDto);
    }

    @ApiOperation(value = "注册")
    @PostMapping("register")
    public Result register(@RequestBody UserInfoDTO userInfoDto){
        return userService.register(userInfoDto);
    }

    @ApiOperation(value = "忘记密码")
    @PostMapping("forget")
    public Result forget(@RequestBody UserInfoDTO userInfoDto){
        return userService.forget(userInfoDto);
    }

    @ApiOperation(value = "发送验证码")
    @PostMapping("getRandom")
    public Result getRandom(String email) {
        return userService.getRandom(email);
    }
    @ApiOperation(value = "退出登录")
    @GetMapping("logout")
    public Result logout(HttpServletRequest request) {
        return userService.logout(request);
    }

    @ApiOperation(value = "更改用户信息")
    @PostMapping("updateUserInfo")
    @Log(name = "更改用户信息")
    public Result updateUserInfo(@RequestBody UserInfoDTO userInfoDTO){
        return userService.updateUserInfo(userInfoDTO);
    }

    @ApiOperation(value = "通过ID删除用户信息")
    @PostMapping("delete")
    @Log(name = "删除用户信息")
    public Result delete(String userIds) {
        return userService.deleteUserInfo(userIds);
    }

    @ApiOperation(value = "查询业主和普通用户")
    @PostMapping("getUserByPosition")
    @Log(name = "查询用户列表")
    public Result getUserByPosition(Boolean isAll,UserInfoDTO userInfoDTO,Boolean isPage){
        return userService.getUserByPosition(isAll,userInfoDTO,isPage);
    }

    @ApiOperation(value = "新增或修改用户")
    @PostMapping("saveOrUpdateById")
    @Log(name = "新增或修改用户信息")
    public Result saveOrUpdateById(@RequestBody UserInfoDTO userInfoDTO){
        return userService.saveOrUpdateById(userInfoDTO);
    }
}

